var score=1;

function getMJType(id) {
    id = parseInt( id );
    if(id >= 0 && id < 9){
        return 0;
    }
    else if(id >= 9 && id < 18){
        return 1;
    }
    else if(id >= 18 && id < 27){
        return 2;
    }
    else if(id >= 27 && id < 34){
        return 3;
    }
    else if(id >= 34 && id < 42){
        return 4;
    }
    return -1;
}
function isHun(mj,hunArr) {
    for(var i=0;i< hunArr.length;i++){
        if(mj == hunArr[i])return true;
    }
    return false;
}
function getPointList(otherNameList){
    //根据牌名获取点数，然后根据点数创建牌
    let displayNameList = ['1筒', '2筒', '3筒', '4筒', '5筒', '6筒', '7筒', '8筒', '9筒', '1条', '2条', '3条', '4条', '5条', '6条', '7条', '8条', '9条', '1万', '2万', '3万', '4万', '5万', '6万', '7万', '8万', '9万', '东', '南', '西', '北', '中', '发', '白'];
    
    let indexList = otherNameList.map( (displayName) =>{
        return displayNameList.indexOf(displayName);
    })
    //去掉无效的牌名，比如十筒
    indexList = indexList.filter( (index) =>{
        return index != -1;
    })
    return indexList;
  }
  function getName(indexList){
    let displayNameList = ['1筒', '2筒', '3筒', '4筒', '5筒', '6筒', '7筒', '8筒', '9筒', '1条', '2条', '3条', '4条', '5条', '6条', '7条', '8条', '9条', '1万', '2万', '3万', '4万', '5万', '6万', '7万', '8万', '9万', '东', '南', '西', '北', '中', '发', '白'];
    
    let indexListName = indexList.map( (item) =>{
        return displayNameList[item];
    }) 
    
    return indexListName;
}

 function sort(arr) {
    arr.sort(function (a,b) {
        return Number(a) - Number(b);
    })
    return arr
}
function sortDesc(arr) {
    arr.sort(function (a,b) {
        return Number(b) - Number(a);
    })
}
function seprateArr( mjArr, hunArr ){
    var reArr = [[],[],[],[]];
    var hunMj = [];
    for(var i=0;i< mjArr.length;i++){
        var mj = mjArr[i];
        if(isHun(mj,hunArr)){
            hunMj.push(mj);
            continue;
        }
        var type = getMJType(mj);
        if(type >=0 && type < 4)
            reArr[type].push( mj );
    }
    reArr[4] = hunMj;
    return reArr
}
function test3Combine( mj1, mj2, mj3 ){
    // console.log(Card.getName([mj1, mj2, mj3]))
    if (mj1 == mj2 && mj1 == mj3){
        return true;
    }
    var t1 = getMJType(mj1), t2 = getMJType(mj2), t3 = getMJType(mj3);
    if (t1 != t2 || t1 != t3){
        return false;
    }
    if (t1 > 2)return false;
    if ((mj1+1) == mj2 && (mj1+2) == mj3){
        return true;
    }
    
    return false;
}

function test2Combine( mj1, mj2 ){
    if (mj1 == mj2){
        return true;
    }
    return false;
}

function getModNeedNum(arrLen,isJiang) {
    if (arrLen == 0) {
        return 0;
    }
    var modNum = arrLen % 3;
    var needNumArr = [0, 2, 1];
    if (isJiang) {
        needNumArr = [2, 1, 0];
    }
    return needNumArr[modNum];
}


var Rule = function() {
    this.hunTotal = 0;
    this.callTime = 0;
    this.needHunCount = 0;
    this.minHunCount = 4;
    this.scores = {}; // 每个分类需要混的数组

};

function getNeedHunInSub( subArr, hNum, rule) {
    rule.callTime += 1;
    var lArr = subArr.length;
    // false 非将牌 可能需要的混子
    if(rule.minHunCount <= hNum + getModNeedNum(lArr, false))return;
    // 缺一色 不需要混子 累计上个需要的混子
    if (lArr == 0) {
        rule.needHunCount = 0 + hNum;
        // 不超过设定的4
        if(rule.needHunCount < rule.minHunCount){
            rule.minHunCount = rule.needHunCount;
        }
        // 出牌权值
        score =1;
        return;
    }
    // 一门一个 需要2个混 花色权值累计1 特殊判定权值100起
    else if (lArr == 1) {
        //不想单吊 赶紧打
        score+=100;
        Object.assign(rule.scores,{[score]:subArr[0]})
        rule.needHunCount = 2 + hNum;
        // 不超过设定的4
        if(rule.needHunCount < rule.minHunCount){
            rule.minHunCount = rule.needHunCount;
        }
        score =1;
        return;
    }
    // 一门2个 形成顺子，刻子 需要1个混 
    else if (lArr == 2) {
        // 判定花色
        var type = getMJType(subArr[0]);
        // 点数
        var mj0 = subArr[0]; 
        var mj1 = subArr[1];
        // 超过常规花色 跳过
        if (type > 2) {
          // 字牌的判断基本不用
            if (mj0 == mj1) {
                rule.needHunCount = 1 + hNum;
                if(rule.needHunCount < rule.minHunCount){
                    rule.minHunCount = rule.needHunCount;
                }
                return;
            }
            else{
                //三不沾
                score+=200;
                Object.assign(rule.scores,{[score]:mj0})
                Object.assign(rule.scores,{[score]:mj1})
                score =1;
                rule.needHunCount = 4 + hNum;
                return;
            }
        }
        else {
          //一个顺子相差 小于等于2 （1,2）（1,1）（1,3）（1,4）
            if (mj1 - mj0 < 3) {
               //补一张 有希望 
                score+=4;
                Object.assign(rule.scores,{[score]:mj0})

                rule.needHunCount = 1 + hNum;
                if(rule.needHunCount < rule.minHunCount){
                    rule.minHunCount = rule.needHunCount;
                }
                score =1;
                return;
            }
            else{
                //三不沾
                score+=200;
                Object.assign(rule.scores,{[score]:mj0})
                Object.assign(rule.scores,{[score]:mj1})

                rule.needHunCount = 4 + hNum;
                score =1;
                return;
            }
        }
    }
    // 一门3个
    else if (lArr >= 3) {
        rule.needHunCount = 2 * lArr;
        var type = getMJType(subArr[0]);
        var mj0 = subArr[0];
        var mj1 = subArr[1];
        var mj2 = subArr[2];
        //第一个和另外两个一铺 【0，2，1】一张牌 需要的2 两张需要的是1 3则是0 将的话 【2，1，0】
            for (var i = 1; i < lArr; i++) {
                var mji = subArr[i];
                //设置权值好去打牌 不相邻最应该大
                //13444   134不可能连一起
                if (mji - mj0 > 1 ){
                    if(hNum >2){
                        score =1;
                        break;     
                    }
                    score+=100;
                    if(i + 1 < lArr){
                        Object.assign(rule.scores,{[score]:mj0})
                        
                    }else{
                        if (mji - subArr[i-1] > 1 ){
                            score+=200;
                            Object.assign(rule.scores,{[score]:mji})
                        }
                    }
                    score =1;
                    break;
                    
                } 
                if (i + 2 < lArr &&　subArr[i + 2] == mji){
                  // 也要打 但是有将、顺的可能 留一手
                  score++;
                  continue;
                }
               
                if (i + 1 < lArr) {
                    var tmp1 = subArr[0], tmp2 = subArr[i], tmp3 = subArr[i + 1];
                    if (test3Combine(tmp1, tmp2, tmp3)) {
                        subArr.splice(0, 1);
                        subArr.splice(i-1, 1);
                        subArr.splice(i-1, 1);
                        getNeedHunInSub(subArr, hNum, rule);
                        subArr.push(tmp1);
                        subArr.push(tmp2);
                        subArr.push(tmp3);
                        sort(subArr);
                    }else{
                      // eg: 679
                      if(tmp2==tmp1 && tmp3!=tmp1){
                        score+=2;
                        Object.assign(rule.scores,{[score]:tmp3})
                        score=1;
                    }else if(tmp2==tmp3 &&  tmp3!=tmp1){
                        score+=2;
                        Object.assign(rule.scores,{[score]:tmp1})
                        score=1;
                    }else{
                        score+=2;
                        Object.assign(rule.scores,{[score]:tmp1})
                        score=1;
                    }
                    }
                }
            }
        //第一个和第二个一铺
        if (hNum + getModNeedNum(lArr - 2, false) + 1 <= rule.hunTotal) {
            if (type > 2) {
                if (mj0 == mj1) {
                    var tmp1 = subArr[0], tmp2 = subArr[1];
                    subArr.splice(0, 1);
                    subArr.splice(0, 1);
                    getNeedHunInSub(subArr, hNum + 1, rule);
                    subArr.push(tmp1);
                    subArr.push(tmp2);
                    sort(subArr);
                }
            }
            else {
                for (var i = 1; i < lArr; i++) {
                    var v1 = subArr[i];
                    //如果当前的value不等于下一个value则和下一个结合避免重复
                    if (i + 1 != lArr) {
                        var v2 = subArr[i + 1];
                        if (v1 == v2)
                            continue;
                    }
                    var mius = v1 - mj0;
                    if (mius < 3) {
                        var tmp1 = subArr[0], tmp2 = subArr[i];
                        subArr.splice(0, 1);
                        subArr.splice(i-1, 1);
                        getNeedHunInSub(subArr, hNum + 1, rule);
                        subArr.push(tmp1);
                        subArr.push(tmp2);
                        sort(subArr);
                        if (mius >= 1) break;
                    }
                    else break;
                }
            }
        }
        //第一个自己一铺
        if (hNum + getModNeedNum(lArr - 1, false) + 2 <= rule.hunTotal) {
            var tmp1 = subArr[0];
            subArr.splice(0, 1);
            getNeedHunInSub(subArr, hNum + 2, rule);
            subArr.push(tmp1);
            sort(subArr);
        }
    }
      
}

function canHu( arr,rule,isCsJiang ) {      //带将
    var arrLen = arr.length;
    if (arrLen == 0) {
        if(rule.hunTotal >= 2 + rule.needHunCount){
            return true;
        }
        return false;
    }
    else if (arrLen == 1) {
        if(rule.hunTotal >= 1 + rule.needHunCount){
            return true;
        }
        return false;
    }
    // 牌数预测混子数
    if (rule.hunTotal < getModNeedNum(arrLen, true) + rule.needHunCount)
        return false;

    var needHunCount = rule.needHunCount;
    rule.minHunCount = 4;
    var hasJiang = false;

    for (var i = 0; i < arrLen; i++) {
        if(isCsJiang){
            const rank = Math.floor(arr[i] % 9);
            hasJiang =  [1,4,7].includes(rank)
        }else{
            hasJiang =true
        }
       
          if (i + 1 < arrLen && arr[i + 1] == arr[i] && hasJiang) {
            var tmp1 = arr[i], tmp2 = arr[i + 1];
            arr.splice(i, 1);
            arr.splice(i, 1);
            getNeedHunInSub(arr, needHunCount, rule);
            arr.push(tmp1);
            arr.push(tmp2);
            sort(arr);
            if (rule.hunTotal >= rule.minHunCount) {
                return true;
            }
        }
        if (rule.hunTotal > needHunCount) {
            if (i + 1 < arrLen && arr[i] != arr[i+1]&& hasJiang) {
                var tmp1 = arr[i];
                arr.splice(i, 1);
                getNeedHunInSub(arr, needHunCount + 1, rule);
                arr.push(tmp1);
                sort(arr);
                if (rule.hunTotal >= rule.minHunCount) {
                    return true;
                }
            }
        }
        if (i + 1 < arrLen && arr[i + 1] == arr[i]) {
            i++;
        }
        if (i + 2 < arrLen && arr[i + 2] == arr[i]) {
            i++;
        }
    }
    return false;
}

//判断胡牌
function doCheckHu( mjArr, hunArr,isCsJiang ){
    var newArr = [].concat(mjArr);
    sort(newArr);
    var sptArr = seprateArr( newArr, hunArr );
    var curHunNum = sptArr[4].length;
    if (curHunNum > 3){
        return true;
    }
    var rule = new Rule();
    rule.hunTotal = curHunNum;
  
    var needHunArr = []; // 每个分类需要混的数组
    var scorestype = []; // 每个分类需要混的数组

    for(var i=0;i<4;i++){
        //算个分数
        score = 1;
        rule.needHunCount = 0;
        rule.minHunCount = 4;

        // 算出每个组合需要的混子
        getNeedHunInSub( sptArr[i], 0 ,rule );
        needHunArr.push(rule.minHunCount);
        scorestype.push(score);
    }
    var isHu = false;
    //将在饼中
    //如果需要的混小于等于当前的则计算将在将在万中需要的混的个数
    var needHunAll = needHunArr[1] + needHunArr[2] + needHunArr[3];
    if (needHunAll <= rule.hunTotal){
        rule.needHunCount = needHunAll;
        isHu = canHu( sptArr[0] ,rule,isCsJiang );
        if (isHu){
            return true;
        }
    }
    //将在条中
    needHunAll = needHunArr[0] + needHunArr[2] + needHunArr[3];
    if (needHunAll <= rule.hunTotal){
        rule.needHunCount = needHunAll;
        isHu = canHu( sptArr[1] ,rule ,isCsJiang);
        if (isHu){
            return true;
        }
    }
    //将在万中
    needHunAll = needHunArr[0] + needHunArr[1] + needHunArr[3];
    if (needHunAll <= rule.hunTotal) {
        rule.needHunCount = needHunAll;
        isHu = canHu(sptArr[2], rule,isCsJiang);
        if (isHu){
            return true;
        }
    }
    //将在风中
    needHunAll = needHunArr[0] + needHunArr[1] + needHunArr[2];
    if (needHunAll <= rule.hunTotal){
        rule.needHunCount = needHunAll;
        isHu = canHu( sptArr[3] ,rule ,isCsJiang);
        if (isHu) {
            return true;
        }
    }
    rule = null;
    return false;
}

function doCheckTing( mjArr, hunArr ,isCsJiang) { //赖子未包括
    var tingMAp = [];
    var isHu = false;
    for(var i=0;i< 27;i++){
        if(isHun(i,hunArr)){
            continue;
        }
        mjArr.push(i);
        isHu = doCheckHu(mjArr, hunArr,isCsJiang);
        mjArr.pop();
        if(isHu){
            tingMAp.push(i);
        }
    }
    return tingMAp;
}

function chiPai( mjArr,pai ) {
    var newArr = [].concat(mjArr);
    var paiType =getMJType(pai);
    sort(newArr);
    var subArr=[]
    var sptArr = seprateArr( newArr,[] );
    for(var i=0;i<4;i++){
        var type = getMJType(sptArr[i]);
        if(type==paiType){
            var targetArr = sptArr[i]
            targetArr.push(pai)
            sort(targetArr);
           // 排列组合看看
           for (let j = 0; j+2 < targetArr.length; j++) {
           // 12 3 45
            var tmp1 = targetArr[j], tmp2 = targetArr[j+1], tmp3 = targetArr[j + 2];
            if ((pai==tmp1 ||pai==tmp2||pai==tmp3) && (tmp1+1) == tmp2 && (tmp1+2) == tmp3){
                subArr.push([tmp1,tmp2,tmp3]);
            }
           }
           break;
        }
    }
    return subArr;
  }
function doAutoChuPai( mjArr, hunArr ) { //赖子未包括
  var isHu = false;
  var newArr = [].concat(mjArr);
  sort(newArr);
  var sptArr = seprateArr( newArr, hunArr );
  var curHunNum = sptArr[4].length;
  var rule = new Rule();
  rule.hunTotal = curHunNum;

  var needHunArr = []; // 每个分类需要混的数组
  var scorestype = []; // 每个分类需要混的数组

  for(var i=0;i<4;i++){
      //算个分数
      score = 1;
      rule.needHunCount = 0;
      rule.minHunCount = 4;
      getNeedHunInSub( sptArr[i], 0 ,rule );
      needHunArr.push(rule.minHunCount);
      scorestype.push(score);
  }
  return rule.scores;
}




const PAI_13YAO = [ 0, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33 ]; //13yao固定牌组
//检测听牌13幺
function check13yao(countMap,hunArr) {
    var tingMap = [];
    var hasHunCount = 0;
    for (var i = 0; i < hunArr.length; i++) {
        var hun = hunArr[i];
        hasHunCount += map[hun];
        map[hun] = 0;
    }
    for(var k=0;k<PAI_13YAO.length;k++) {
        var pai = PAI_13YAO[k];
        if (isHun(pai,hunArr)) {
            continue;
        }
        var needHunCount = 0;
        var leftCard = -1;
        var map = [].concat(countMap);
        map[pai] ++;
        for (var i = 0; i < PAI_13YAO.length; i++) {
            var pai2 = PAI_13YAO[i];
            if (map[pai2] == 0) {
                needHunCount++;
            }
            else if (map[pai2] > 2) {
                return [];
            }
            else if (map[pai2] == 2) {
                if (leftCard != -1) {
                    return [];
                }
                leftCard = pai2;
            }
        }
        if (hasHunCount >= needHunCount) {
            if (leftCard != -1) {
                tingMap.push(pai);
            }
            else if (hasHunCount > needHunCount) {
                tingMap.push(pai);
            }
        }
    }
    return tingMap;
}
var MAX_MJ=27;
//检测听牌7对
function check7dui( holds, hunArr ) {
    //检查是否是七对 前提是没有碰，也没有杠 ，即手上拥有13张牌
    if( holds.length != 13 )return [];
    var tingMap = [];
    var hasHunCount = 0;
    var holds2 = [].concat(holds);
    for (var j = 0; j < holds2.length; j++) {
        if (isHun(holds2[j],hunArr)) {
            hasHunCount++;
            holds2.splice(j, 1);
            j--;
        }
    }
    // 5 6 6 6 7 7
    for(var k=0;k<MAX_MJ;k++) {
        if (isHun(k,hunArr)) {
            continue;
        }
        var needHunCount = 0;
        var holds3 = [].concat(holds2);
        holds3.push(k);
        sort(holds3);
        for (var j = 0; j < holds3.length; j++) {
            if (j + 1 < holds3.length && holds3[j + 1] == holds3[j]) {
                j++; 
            }
            else {
                needHunCount++;
            }
        }
        if (hasHunCount >= needHunCount) {
            tingMap.push(k);
        }
    }
    return tingMap;
}
//检测听牌7对
function checkSuper7dui( holds, hunArr ) {
    //检查是否是七对 前提是没有碰，也没有杠 ，即手上拥有13张牌
    if( holds.length != 13 )return [];

    var tingMap = [];

    var holds3 = [].concat(holds);

    sort(holds3);
    for (var j = 0; j < holds3.length; j++) {
        if (j + 1 < holds3.length && holds3[j + 1] == holds3[j] &&holds3[j + 1] == holds3[j+2]) {
            tingMap.push(holds3[j])
            holds3.splice(j, 1);
            holds3.splice(j, 1);
            holds3.splice(j, 1);
        }
        
        
    }
    return tingMap;
}
//检测将将胡 //手上都是将啊
function checkJiangJiang( holds, hunArr,seatData ) {
    if(seatData.chi && seatData.chi.length>0){
        return []
    }
    var holds2 = [].concat(holds);
    let hasJiang =true;
    let hasHunCount =0;
    var tingMap = [];

    for (var j = 0; j < holds2.length; j++) {
        if (isHun(holds2[j],hunArr)) {
            hasHunCount++;
            holds2.splice(j, 1);
            j--;
        }
    }

    for (let index = 0; index < seatData.penggangs.length; index++) {
        const element = seatData.penggangs[index];
        hasJiang =  [1,4,7].includes(element[1])
        if(!hasJiang){
          
            break;
        }
      }
    for (var i = 0; i < holds2.length; i++) {
        const rank = Math.floor(holds2[i] % 9);
        hasJiang =  [1,4,7].includes(rank)
        if(!hasJiang){
          
            break;
        }
    }
    if(hasJiang){
        for(var k=0;k<MAX_MJ;k++) {
            if (isHun(k,hunArr)) {
                continue;
            }
            const rank = Math.floor(k % 9);
            const hasJiang =  [1,4,7].includes(rank)
            if(hasJiang){
                tingMap.push(k)
            }
          
        }
    }
    
    return tingMap;
}
//检测碰碰胡
function checkPengPeng( holds, hunArr ,seatData) {
    if(seatData.chi && seatData.chi.length>0){
        return []
    }
    var tingMap = [];
    var hasHunCount = 0;

    var holds2 = [].concat(holds);

    for (var j = 0; j < holds2.length; j++) {
        if (isHun(holds2[j],hunArr)) {
            hasHunCount++;
            holds2.splice(j, 1);
            j--;
        }
    }
    var holds3 = [].concat(holds2);
    // console.log("判断碰碰胡:", Card.getName(holds3));

    //  穷举 把三张一样的移除  两种情况 1+1,4+1 
    for (var j = 0; j < holds3.length; j++) {
        if (j + 2 < holds3.length && holds3[j + 1] == holds3[j] && holds3[j + 2] == holds3[j]) {
            holds3.splice(j, 1);
            holds3.splice(j, 1);
            holds3.splice(j, 1);
            j--
        }
    }
    for(var k=0;k<holds3.length;k++) {
        let m =holds3[k];
        var needHunCount = 0;

        var holds4 = [].concat(holds3);
        holds4.push(m);
        sort(holds4);
        for (var j = 0; j < holds4.length; j++) {
            if (j + 2 < holds4.length && holds4[j + 1] == holds4[j] && holds4[j + 2] == holds4[j]) {
                holds4.splice(j, 1);
                holds4.splice(j, 1);
                holds4.splice(j, 1);
                j--;
            }else{
                if (j + 1 < holds4.length && holds4[j + 1] == holds4[j] ) {
                    holds4.splice(j, 1);
                    holds4.splice(j, 1);
                    j--;
                } 
            }
        }
        // 移除后应该剩一对
        if (holds4.length==2 && holds4[0] == holds4[1]) {
            if(!tingMap.includes(m)){
                tingMap.push(m);
            }
         
        }else{
            //有红中情况
            if (holds4.length==0&&hasHunCount >= 0) {
                if(!tingMap.includes(m)){
                    tingMap.push(m);
                }
            }

        }
    }
    return tingMap;
}
function checkQuanQiuRen( holds, hunArr ) {

    if( holds.length != 1 )return [];
    return holds;
}
function checkQingYiSe( holds, hunArr ,seatData) {
    var temp=false
    var noSuit=1
    var hasHunCount=0
    var holds2 = [].concat(holds);

    for (var j = 0; j < holds2.length; j++) {
        if (isHun(holds2[j],hunArr)) {
            hasHunCount++;
            holds2.splice(j, 1);
            j--;
        }
    }
    var holds3 = [].concat(holds2);
    //摆出去的
    for (let index = 0; index < seatData.penggangs.length; index++) {
        const element = seatData.penggangs[index];
        if (getMJType(holds3[0]) != getMJType(element[1])) {
            return [];
        }
    }
    //摆出去的
    // console.log(seatData)
    seatData.chi =seatData.chi?seatData.chi:[]
    for (let index = 0; index < seatData.chi.length; index++) {
        const element = seatData.chi[index];
        if (getMJType(holds3[0]) != getMJType(element[1])) {
            return [];
        }
    }
    //手上的
    for (var j = 0; j < holds3.length; j++) {
        if (j+1<holds3.length && getMJType(holds3[j+1]) == getMJType(holds3[j])) {
            noSuit++;
        }
    }
    
    if((noSuit) ==holds3.length){
        let isHu = doCheckTing(holds, [31],false); //检查平胡
        return isHu;

    }
    return [];
}



//  板板胡、缺一色、大四喜(中途)、六六顺(中途)  单五一枝花 （某花色仅有一张牌）
//板板胡
function checkBanBanHu( holds, hunArr ) {
    
    if(holds.length < 13)return false
    var holds2 = [].concat(holds);
    let hasJiang =false;
    for (var i = 0; i < holds2.length; i++) {
        if (isHun(holds2[i],hunArr)) {
            hasJiang=true
           break
        }
        const rank = Math.floor(holds2[i] % 9);
        hasJiang =  [1,4,7].includes(rank)
        if(hasJiang){
          
            break;
        }
    }
    return !hasJiang;
}
//缺一色
function checkQueYiSe( holds, hunArr ) {
    if(holds.length < 13)return false
    var noSuit={}
    var holds3 = [].concat(holds);
    for (var j = 0; j < holds3.length; j++) {
        noSuit={...noSuit,[getMJType(holds3[j])]:1}
    }
    return Object.keys(noSuit).length>2?false:true;
}

//单五一枝花 
function checkYiZhiHua( holds, hunArr ) {
    if(holds.length < 13)return false
    var holds2 = [].concat(holds);
    let hasHun =false;
    let has5Jiang =false;
    var count=0;
    var noSuit={}

    for (var i = 0; i < holds2.length; i++) {
        if (isHun(holds2[i],hunArr)) {
            hasHun=true
           continue
        }
        var count:number= noSuit[getMJType(holds2[i])]?noSuit[getMJType(holds2[i])]:0
        noSuit={...noSuit,[getMJType(holds2[i])]:Number(count)+1}
    }
    var suit = Object.keys(noSuit).find(item=>noSuit[item]==1)
    for (var j = 0; j < holds2.length; j++) {
        if(getMJType(holds2[j])==noSuit[suit]){
            const rank = Math.floor(holds2[j] % 9);
            has5Jiang =  [4].includes(rank)
            break;
        }
    }
    var queyise = checkQueYiSe(holds, hunArr)
    return (!hasHun && has5Jiang)||(hasHun && queyise);
}


// 中途操作
function checkDaSiXi( holds, hunArr ) {
    var hasHunCount = 0;
    var holds2 = [].concat(holds);

    for (var j = 0; j < holds2.length; j++) {
        if (isHun(holds2[j],hunArr)) {
            holds2.splice(j, 1);
            j--;
        }
    }
    var holds3 = [].concat(holds2);

    for (var j = 0; j < holds3.length; j++) {
        if (j + 3 < holds3.length && holds3[j + 1] == holds3[j] && holds3[j + 2] == holds3[j]&& holds3[j + 3] == holds3[j]) {
            //移除累加否则 4个有影响
            holds3.splice(j, 1);
            holds3.splice(j, 1);
            holds3.splice(j, 1);
            holds3.splice(j, 1);
            hasHunCount ++;
            j--
        }
    }
    
    
    return hasHunCount>0?true:false;
}
// 六六顺(中途)
function check66Shun( holds, hunArr ) {
    var hasHunCount = 0;
    var holds2 = [].concat(holds);

    for (var j = 0; j < holds2.length; j++) {
        if (isHun(holds2[j],hunArr)) {
            holds2.splice(j, 1);
            j--;
        }
    }
    var holds3 = [].concat(holds2);

    for (var j = 0; j < holds3.length; j++) {
        if (j + 2 < holds3.length && holds3[j + 1] == holds3[j] && holds3[j + 2] == holds3[j]) {
            //移除累加否则 4个有影响
            holds3.splice(j, 1);
            holds3.splice(j, 1);
            holds3.splice(j, 1);
            hasHunCount ++;
            j--
        }
    }
    
    
    return hasHunCount>1?true:false;
}



export const checkHu ={
 sort,
 getName,
 getPointList,
 doCheckHu,
 doCheckTing,
 doAutoChuPai,
 sortDesc,
 checkBanBanHu,
 checkQueYiSe,
 checkYiZhiHua,

// 7对、豪7对、将将胡、碰碰胡、全求人、清一色
 check13yao,
 check7dui,
// 豪7对：
// 7对的基础上判断有没有4个一样的点数
 checkSuper7dui,
// 将将胡：（游戏服务器数据判断）
// 手上13张牌包括碰也是将（2.5.8） 就是将将胡
 checkJiangJiang,
// 碰碰胡：（游戏服务器数据判断，keys 3*n+2）
// 全是刻子没有顺子+一对
 checkPengPeng,

// 全求人：（游戏服务器数据判断）
// 只剩一张
 checkQuanQiuRen,

// 清一色
// 花色一样
 checkQingYiSe,

 checkDaSiXi,
 check66Shun,
 chiPai,
}